# Maintainer: Justin Kromlinger <hashworks@archlinux.org>

pkgname=opensearch-anomaly-detection-plugin
pkgver=2.6.0.0
pkgrel=1
_opensearchver=2.6.0
_jdkver=11
pkgdesc="OpenSearch Anomaly Detection Plugin"
arch=('loong64' 'x86_64')
url="https://opensearch.org/docs/latest/monitoring-plugins/ad"
license=('Apache')
depends=("opensearch=${_opensearchver}")
makedepends=("java-environment=${_jdkver}" 'unzip')
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/opensearch-project/anomaly-detection/archive/${pkgver}.tar.gz"
)
sha256sums=('8719f7a35260ad27991b6df743bfbff318398c87edf7f4a81284e1054ddf4d5d')

build() {
  cd "anomaly-detection-${pkgver}"
  export JAVA_HOME="/usr/lib/jvm/java-${_jdkver}-openjdk"
  export PATH="/usr/lib/jvm/java-${_jdkver}-openjdk/bin:$PATH"
  export GRADLE_OPTS="-Dbuild.snapshot=false -Dopensearch.version=${_opensearchver}"
  # integTest (Reaper) requires JDK 14
  ./gradlew assemble \
    --exclude-task ":integTest" \
    --exclude-task ":jacocoTestReport"
}

package() {
  install -dm755 "${pkgdir}/usr/share/opensearch/plugins/opensearch-anomaly-detection"
  cd "${pkgdir}/usr/share/opensearch/plugins/opensearch-anomaly-detection"
  unzip "${srcdir}/anomaly-detection-${pkgver}/build/distributions/opensearch-anomaly-detection-${pkgver}.zip"

  install -Dm644 "${srcdir}/anomaly-detection-${pkgver}/LICENSE.txt" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt"
}
